<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>

          <a-col :md='4' :sm='8'>
            <a-form-item label='冷库' :labelCol='{span: 5}' :wrapperCol='{span: 18, offset: 1}'>
              <j-dict-select-tag type='list' v-model='queryParam.storehouse' :trigger-change='true'
                                 dictCode='flower_storehouse,name,code' placeholder='请选择冷库' />
            </a-form-item>
          </a-col>
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-item label='产品'>
              <a-input placeholder='请输入产品' v-model='queryParam.variety'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-item label='产品编码'>
              <a-input placeholder='请输入产品编码' v-model='queryParam.varietyCode'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='入库时间'>
              <a-range-picker :style="{width: '100%'}" format='YYYY-MM-DD'
                              :placeholder="['开始时间', '结束时间']"
                              v-model='rangePikerDate'
                              @change='onQueryDateChange' />
            </a-form-item>
          </a-col>
          <!--          <a-col :md="4" :sm="8">
                      <a-form-item label="状态" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                        <j-dict-select-tag v-model="queryParam.state" placeholder="请选择状态"
                                           dictCode="planting_flower_state"/>
                      </a-form-item>
                    </a-col>-->
          <template v-if='toggleSearchStatus'>
            <!--    <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="分拣日期">
                  <j-date placeholder="请选择分拣日期" v-model="queryParam.sortTime"></j-date>
                </a-form-item>

              </a-col>-->

            <a-col :xl='4' :lg='7' :md='8' :sm='24'>
              <a-form-item label='单位'>
                <a-input placeholder='请输入单位' v-model='queryParam.flowerPoleLength'></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button type='primary' icon='download' @click="handleExportXlsAll('库存实时台账信息')">导出Excel</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref='table'
        size='middle'
        bordered
        :rowKey='record => record.sourceGreenhouse +record.storehouse + record.varietyCode'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :footer='getfooterinfo'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='uploadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <!--        <template slot="footer"  slot-scope="text, record">
                  <a-col style='color: red; text-align: center'>  合计 ：record.sorter   </a-col>
                </template>-->

      </a-table>
    </div>

    <!--    <flowerTagInfo-modal ref="modalForm" @ok="modalFormOk"></flowerTagInfo-modal>-->
    <PrintTemplate v-show='printShow'></PrintTemplate>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JDate from '@/components/jeecg/JDate.vue'
import { downFile } from '@/api/manage'
import { queryFlowerBase, queryGreenhouseByPd } from '@/api/vegetableAPI'

export default {
  name: 'FlowerTagInfoList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
    JDate,
  },
  data() {
    return {
      printShow: false,
      baseList: [], //基地信息
      greenhouseList: [], //大棚信息
      rangePikerDate: [],
      description: '总台账管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        }, {
          title: '基地',
          align: 'center',
          dataIndex: 'sourceBase_dictText'
          // width: 120,
        }, {
          title: '大棚',
          align: 'center',
          dataIndex: 'sourceGreenhouse_dictText'
          // width: 100,
        }, {
          title: '冷库',
          align: 'center',
          dataIndex: 'storehouse_dictText'
          // width: 120,
        },
        {
          title: '批次',
          align: 'center',
          dataIndex: 'productionId'
          // width: 120,
        },
        {
          title: '采收产品',
          align: 'center',
          dataIndex: 'variety'
          // width: 100,
        },
        {
          title: '产品编码',
          align: 'center',
          dataIndex: 'varietyCode'
          // width: 100,
        }, {
          title: '打包规格',
          align: 'center',
          dataIndex: 'packingSpecifications'
          // width: 100,
        }, {
          title: '等级',
          align: 'center',
          dataIndex: 'classes'
        }, {
          title: '库存数',
          align: 'center',
          dataIndex: 'number',
          width: 100
        }, {
          title: '锁定数',
          align: 'center',
          dataIndex: 'lockNumber',
          width: 100
        }, {
          title: '可用数',
          align: 'center',
          dataIndex: 'ableNumber',
          width: 100
        }, {
          title: '单位',
          align: 'center',
          dataIndex: 'flowerPoleLength',
          width: 60
        }


      ],
      url: {
        // list: "/flower/tagInfo/getListByhose", // list: "/flower/tagInfo/list",
        list: '/flower/flowerTagBook/list', //
        exportXlsUrl: '/flower/flowerTagBook/exportXls'
      },
      dictOptions: {},
      totalinfos: ''
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.initBaseInfo()
  },
  methods: {
    openModal() {
      this.printShow = true
    },
    printP() {
      window.print()
    },
    //初始化基地信息
    initBaseInfo() {
      queryFlowerBase().then((res) => {
        if (res.success) {
          this.baseList = res.result
        }
      })
    },
    handleChange(value) {
      queryGreenhouseByPd(value).then((res) => {
        if (res.success) {
          this.greenhouseList = res.result
        }
      })
    },
    initDictConfig() {
    },
    onQueryDateChange(date, dateString) {// 日期段选择改变时的回调
      this.queryParam.sDate = dateString[0]
      this.queryParam.eDate = dateString[1]
    },
    handleExportXlsAll(fileName) {

      let param = this.queryParam

      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      let urlss = this.url.exportXlsUrl
      downFile(urlss, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xlsx')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    getfooterinfo(record) {
      if (this.dataSource) {
        let heji = 0
        if (this.dataSource.length > 0) {
          heji = this.dataSource[0].heji
        }
        // return "合计："+ this.dataSource[0].sorter
        return <a-col style='color: red; text-align: right;padding-right:80px;'>  {heji}   </a-col>
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>